#coding: utf-8

import sys
import os.path 

cur_path = os.path.dirname(__file__)
parent_path = os.path.abspath(os.path.join(cur_path, '..'))
sys.path.append(parent_path)

import time
import pymongo
import redis
from topapi import *
from exceptions import Exception


#get the string list of the last n days, begin with yesterday
def last_n_days(n):
    r = []
    for i in range(n):
        x = time.time() - (i+1) * 86400 
        x = time.strftime('%Y-%m-%d', time.localtime(x))
        r.append(x)
    return r


def n_redis_keys(iid, n):
    r = []
    str_iid = str(iid)
    for i in range(n):
        x = time.time() - (i+1) * 86400 
        x = time.strftime('%Y-%m-%d', time.localtime(x))
        r.append(':'.join([str_iid, x]))
    return r

def test_n_redis_keys():
    print n_redis_keys(1234567, 30)
    print last_n_days(10)


if __name__ == '__main__':
    test_n_redis_keys()


